<?php
namespace Home\Controller;
use Think\Verify;

class PublicController extends BaseController{
	//访问统计
	public function visit(){
		$Visit = D('Admin/Visit');
		if ($Visit->yesterday()){
			$output = '"IP","访问页面","当日次数","第一次","最后一次",';
			$object = $Visit->all2();
			if ($object){
				import('Yvjie.QQWry');
				$QQWry = \QQWry::getInstance();
				foreach ($object as $value){
					$output .= "\r\n".'"'.$value['ip'].' -- '.$QQWry->getAddr($value['ip']).'","'.htmlspecialchars_decode($value['url']).'","'.$value['count'].'","'.dateFormat($value['date1']).'","'.dateFormat($value['date2']).'",';
				}
			}
			$output = mb_convert_encoding($output,'GBK','UTF-8');
			$file = C('OUTPUT_DIR').'visit_'.date('YmdHis').'.csv';
			if (file_put_contents(ROOT_PATH.'/'.$file,$output)) $Visit->truncate();
		}
		$object = $Visit->one();
		$object ? $Visit->update($object['id']) : $Visit->insert();
		exit;
	}
	
	/* //地区级联
	public function district(){
		if (IS_AJAX){
			$District = D('Admin/District');
			$this->ajaxReturn($District->all2());
		}
	} */
	
	//QQ登录
	public function qq(){
		include ROOT_PATH.'/ThinkPHP/Library/Yvjie/qq/comm/utils.php';
		include ROOT_PATH.'/ThinkPHP/Library/Yvjie/qq/class/QC.class.php';
		$qc = new \QC('','',C('WEB_URL').'Callback/qqHome.php');
		$qc->qq_login();
	}
	
	//QQ登录返回
	public function qqReturn(){
		include ROOT_PATH.'/ThinkPHP/Library/Yvjie/qq/comm/utils.php';
		include ROOT_PATH.'/ThinkPHP/Library/Yvjie/qq/class/QC.class.php';
		$qc = new \QC('','',C('WEB_URL').'Callback/qqHome.php');
		$callback = $qc->qq_callback();
		$openid = $qc->get_openid();
		if ($callback && $openid){
			$jsDir = C('TMPL_PARSE_STRING');
			exit('<script type="text/javascript" src="'.$jsDir['__PUBLICJS__'].'/jquery.js"></script><script type="text/javascript">$(function(){$(".info2",window.opener.document).hide();$(".submit img",window.opener.document).hide();$(".info1",window.opener.document).show();$(".submit input",window.opener.document).show();window.close();});</script>');
		}
	}
	
	//验证码
	public function verify(){
		ob_clean();
		$Template = D('Admin/Template');
		$object = $Template->one();
		if ($object){
			$verifySet = explode(',',$object['verify']);
			if ($verifySet[0]){
				$Verify = new Verify();
				if ($verifySet[1] == 1){
					$Verify->fontttf = 'msyhbd.ttf';
					$Verify->useZh = true;
				}
				/*$Verify->useCurve = false;
				$Verify->useNoise = false;*/
				$Verify->imageW = $verifySet[2];
				$Verify->imageH = $verifySet[3];
				$Verify->length = $verifySet[4] ? $verifySet[4] : 4;
				$Verify->fontSize = $verifySet[5] ? $verifySet[5] : 25;
				$Verify->entry(I('get.id'));
			}
		}
	}
	public function verify2(){
		ob_clean();
		$Verify = new Verify();
		$Verify->imageW = 200;
		$Verify->imageH = 62;
		$Verify->entry(10000000);
	}
}